package com.xywy.wjk.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xywy.R;
import com.xywy.wjk.bean.AddData;

import java.util.List;

/**
 * 云健康  -  右侧，添加数据
 */
public class AddDataAdapter extends BaseAdapter {

    private Context mContext;
    private List<AddData> list;
    public AddDataAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    public void setData(List<AddData>  stringList){
        this.list = stringList;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Hold hold;
        if(convertView==null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.wjk_add_item, null);

            hold = new Hold();

            hold.check= (ImageView) convertView.findViewById(R.id.iv_wjk_detail_add_item);
            hold.title = (TextView) convertView.findViewById(R.id.tv_wjk_detail_add_item);
            convertView.setTag(hold);
        }else{
            hold = (Hold) convertView.getTag();
        }
        final AddData  data=list.get(position);
          if(data.isChecked()){
               hold.check.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.wjk_add_dian_pressed));
          }else{
              hold.check.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.wjk_add_dian));
          }
        hold.title.setText(data.getTitle());
        return convertView;
    }
    public class Hold{
          ImageView check;
          TextView  title;
    }

}
